﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatabaseManager.Data.Mappings
{
    public class UserMap : IEntityTypeConfiguration<User>
    {
        public void Configure(EntityTypeBuilder<User> builder)
        {
            // 设置表名
            builder.ToTable("Users");

            // 主键配置
            builder.HasKey(u => u.Id);

            // 属性映射
            builder.Property(u => u.Id)
                   .HasColumnName("UserId")
                   .ValueGeneratedOnAdd();

            builder.Property(u => u.Username)
                   .IsRequired()
                   .HasMaxLength(50)
                   .HasColumnName("Username");

            builder.Property(u => u.Email)
                   .IsRequired()
                   .HasMaxLength(100)
                   .HasColumnName("Email");

            builder.Property(u => u.CreatedAt)
                   .IsRequired()
                   .HasColumnName("CreatedAt");

            // 示例：可选字段
            builder.Property(u => u.Bio)
                   .HasMaxLength(500)
                   .IsRequired(false)
                   .HasColumnName("Bio");
        }
    }
}
